#include <vector>
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int firstDuplicateValue(vector<int> array){
    set<int> buf;
    for(int n:array){
        auto pair=buf.insert(n);
        if(!pair.second){
            return n;
        }
    }
    return 0;
}

int main(int argc, char const *argv[])
{
    set<int> s;
    pair<set<int>::iterator, bool>result=s.insert(5);
    cout<<*result.first<<endl;
    cout<<result.second<<endl;
    
    result = s.insert(5);

    cout<<"第二次插入5："<<result.second<<endl;
    for(int n:s){
        cout<<n<<"";
    }
    cout<<endl;
    
    vector<int> v{1,2,3,4,5,2};
    cout<<firstDuplicateValue(v)<<endl;
    return 0;
}

